import { cloudType, ResultCommon, ResultPagination } from "@/utils/commonType";
import { http } from "@/utils/http";
import { baseUrlApi } from "@/utils/http/utils";


/** 获取系统管理-服务云管理列表 */
export const getCloudList = async (tenantId, data?: object) => {
  const result = await http.request<ResultPagination<cloudType>>(
    "get",
    baseUrlApi("/cloud/list/" + tenantId),
    {
      params: data
    }
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};
export const getCloudByTenant = async (tenantId) => {
  const data = await getCloudList(tenantId, { page: 1, pageSize: 1000 })
  return data.data.list;
};
export const changeCloudStatus = async (
  cloudId: string,
  cloudStatus: string
) => {
  let reqUri = "";
  if (cloudStatus === "active") {
    reqUri = "/cloud/active/" + cloudId;
  } else {
    reqUri = "/cloud/archive/" + cloudId;
  }
  const result = await http.request<ResultCommon<cloudType>>("put", baseUrlApi(reqUri));
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};


export const addCloud = async (
  data: cloudType
) => {

  const result = await http.request<ResultCommon<cloudType>>("post", baseUrlApi("/cloud/add"), { data });
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};

export const updateCloud = async (
  data: cloudType,
  cloudId: string
) => {
  const result = await http.request<ResultCommon<cloudType>>("put", baseUrlApi("/cloud/update/" + cloudId), { data });
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};